//
//  GNStatus.swift
//  SinaWeChat
//
//  Created by mac on 15/12/10.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class GNStatus: NSObject {
    
     // 注意在 iPhone5 上,系统架构是32位,使用 int 系统会使用的是 int32 -> 微博id已经超出了
    var id: Int64 = 0
    
    //微博的内容
    
    var text : String?
    //当前微博作者信息
    var user : GNUser?
    
    //微博的创建时间
    var created_at: String?
    
    //来自
    var source: String?
    
    //转发
     var reposts_count: Int = 0
    
    //评论数
    var comments_count: Int = 0
    
    //表态数
    var attitudes_count: Int = 0
    
    //转发微薄的内容(同样是一个GNStatus)
     var retweeted_status: GNStatus?
    
    //当前微博的配图
    var pic_urls : [GNStatusPictureInfo]?
    
    init(dict:[String:AnyObject]) {
        
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user"{
            
            if let dict = value as? [String:AnyObject]{
                user = GNUser(dict: dict)
            }
        }else if key == "retweeted_status"{
            if let dict = value as? [String: AnyObject] {
                retweeted_status = GNStatus(dict: dict)
            }
        }else if key == "pic_urls"{
            
            //判断当前的value是否一个数组
            
            if let array = value as? [[String: AnyObject]] {
                
                //定义临时数组
                var tempArray = [GNStatusPictureInfo]()
                
                //遍历
                for dict in array {
                    //进行字典转模型,并保存
                    
                    tempArray.append(GNStatusPictureInfo(dict: dict))
                    
                }
                pic_urls = tempArray
                
            }
            
        }else{
            super.setValue(value,forKey:key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    override var description : String {
        
        let keys = ["text","retweeted_status"]
        
        return dictionaryWithValuesForKeys(keys).description
    }
}
